package com.siwei.mes.service.erp.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.entity.erp.RwdextraExtend;
import com.siwei.mes.entity.erp.RwdextraExtendUpdateLog;
import com.siwei.mes.mapper.erp.RwdextraExtendUpdateLogMapper;
import com.siwei.mes.service.erp.RwdextraExtendUpdateLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * ERP任务单扩展信息修改记录(RwdextraExtendUpdateLog)表服务实现类
 *
 * @author linzi
 * @since 2024-08-20 22:59:50
 */
@Service
public class RwdextraExtendUpdateLogServiceImpl implements RwdextraExtendUpdateLogService {
    @Resource
    private RwdextraExtendUpdateLogMapper rwdextraExtendUpdateLogMapper;

    @Override
    public void insertLog(Integer frwdh, RwdextraExtend beforeInfo, RwdextraExtend afterInfo) {
        RwdextraExtendUpdateLog entity = new RwdextraExtendUpdateLog();
        entity.setFrwdh(frwdh);
        if (beforeInfo != null) {
            entity.setBeforeJson(JsonUtils.beanToObject(beforeInfo));
        }
        if (afterInfo != null) {
            entity.setAfterJson(JsonUtils.beanToObject(afterInfo));
        }
        entity.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null);
        entity.setCreateTime(new Date());
        rwdextraExtendUpdateLogMapper.insertSelective(entity);
    }
}
